<template>
  <div class="modify-dialog">
    <slot></slot>
    <el-dialog
        :close-on-click-modal="false"
        v-bind="dialogOpts" :visible.sync="dialogVisible">
      <Form v-bind="formOpts" v-on="formEvent">
        <template #formSuf>
          <el-form-item label="产品" style="width: 100%">
            <ProductInput
                api="newOrderOutMaterials"
                :params="{ id: row.id }"
                v-model="arr"
            />
          </el-form-item>
        </template>
        <template #formBtn>
          <div class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" v-preventReClick @click="onConfirm"> 确 定</el-button>
          </div>
        </template>
      </Form>
    </el-dialog>
  </div>
</template>

<script>
import ProductInput from "./ProductInput.vue";
import modifyMixins from "@/mixins/modifyMixins.vue";

export default {
  mixins: [modifyMixins],
  components: {
    ProductInput,
  },
  data() {
    return {
      dialogTitle: "确认订单",
      labelPosition: "left",
      dialogWidth: "50vw",
      form: {},
    };
  },
  computed: {},
  methods: {
    onSubmit(form) {
      this.$message({message: "正在确认库存，请耐心等候！", type: "warning"})
      let {modify, row} = this;
      const materials = this.arr
          .filter((e) => e.id && e.count)
          .map((e) => {
            return {id: e.id, count: e.count, norms: e.norms, productCode: e.productCode};
          });
      if (!materials.length) return this.$message.error("请完善产品输入");
      form.id = row.id;
      form.orderId = row.id;
      form.status = 0;
      // form.outMaterialsList = materials;
      this.$api.orderConfirmOrderSenior(form).then(res => {
        if (res == 505) {
          this.$message({message: "产品库存不足，无法确认订单，已发送短信给仓库主管!", type: "warning"})
        } else {
          form = {}
          this.submitDoneMsg()
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
</style>

